﻿namespace Example.Cryptography
{
    using System;
    using System.Text;

    using Xunit;

    public class ShaCiphertextFacts
    {
        [Fact]
        public void ctor_SaltNull_byte()
        {
            Assert.Throws<ArgumentNullException>(() => new ShaCiphertext(null, new byte[] { 1, 2, 3 }));
        }

        [Fact]
        public void ctor_Salt_byte()
        {
            Assert.NotNull(new ShaCiphertext(
                               Salt.Fresh(), 
                               new byte[] { 1, 2, 3 }));
        }

        [Fact]
        public void ctor_Salt_byteEmpty()
        {
            Assert.NotNull(new ShaCiphertext(
                               Salt.Fresh(), 
                               new byte[] { }));
        }

        [Fact]
        public void ctor_Salt_byteNull()
        {
            Assert.Throws<ArgumentNullException>(() => new ShaCiphertext(Salt.Fresh(), null));
        }

        [Fact]
        public void op_ToBytes()
        {
            var expected = Encoding.UTF8.GetBytes("test");
            var actual = new ShaCiphertext(Salt.Fresh(), expected).ToBytes();

            Assert.Equal(expected, actual);
        }

        [Fact]
        public void op_ToString()
        {
            var ciphertext = Encoding.UTF8.GetBytes("test");

            var expected = Convert.ToBase64String(ciphertext);
            var actual = new ShaCiphertext(Salt.Fresh(), ciphertext).ToString();

            Assert.Equal(expected, actual);
        }
    }
}